package powell.nflpredictionproject.display;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.*;

/*
 * This class displays the results of the last five weeks of a team's schedule
 * to the user.
 */
public class FiveGameResultPanel
        extends JFrame
{

    private ImageIcon imageIcon = new ImageIcon("NFLL.JPG");
    private JLabel output1 = new JLabel();
    private JLabel output2 = new JLabel();
    private JLabel output3 = new JLabel();
    private JLabel output4 = new JLabel();
    private JLabel output5 = new JLabel();
    private JButton reset = new JButton("Reset");
    private JButton exit = new JButton("Exit");
    private JPanel buttonPanel = new JPanel();
    private JPanel resultPanel = new JPanel();
    private JPanel imagePanel = new JPanel(new BorderLayout());
    private JLabel pictureLbl = new JLabel(imageIcon);

    /*
     * This is the constructor for the FiveGameResultPanel.
     * 
     * @param text1
     * @param text2
     * @param text3
     * @param text4
     * @param text5
     */
    public FiveGameResultPanel(String text1,
            String text2,
            String text3,
            String text4,
            String text5)
    {
        this.setBounds(200, 100, 1000, 870);

        reset.setToolTipText("ALT-R to Reset");
        reset.setMnemonic(KeyEvent.VK_R);

        exit.setToolTipText("ALT-E to Exit");
        exit.setMnemonic(KeyEvent.VK_E);

        /*
         * This part of the constructor is setting the JLabels to the values
         * passed to the constructor and then setting the foreground to white
         * for all the JLabels.
         */
        output1.setText(text1);
        output2.setText(text2);
        output3.setText(text3);
        output4.setText(text4);
        output5.setText(text5);

        /*
         * This part of the constructor is building the JFrame.
         */
        BuildPanels();

        output1.setFont(new Font("Serif", Font.PLAIN, 18));
        output2.setFont(new Font("Serif", Font.PLAIN, 18));
        output3.setFont(new Font("Serif", Font.PLAIN, 18));
        output4.setFont(new Font("Serif", Font.PLAIN, 18));
        output5.setFont(new Font("Serif", Font.PLAIN, 18));

        this.setTitle("Five Week Prediction");

        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        this.setLayout(new GridLayout(3, 1));

        this.add(imagePanel);
        this.add(resultPanel);
        this.add(buttonPanel);

        this.setResizable(false);

        this.setVisible(true);
    }

    /*
     * This method builds the JPanels needed for this JFrame.
     */
    public void BuildPanels()
    {
        reset.addActionListener(new ButtonListener());
        exit.addActionListener(new ButtonListener());

        imagePanel.add(pictureLbl, BorderLayout.CENTER);

        imagePanel.setBackground(Color.BLACK);

        buttonPanel.add(reset);
        buttonPanel.add(exit);

        buttonPanel.setBackground(Color.BLACK);

        resultPanel.setLayout(new GridLayout(5,
                1));

        resultPanel.setBackground(Color.BLACK);

        resultPanel.add(output1);
        resultPanel.add(output2);
        resultPanel.add(output3);
        resultPanel.add(output4);
        resultPanel.add(output5);

        output1.setForeground(Color.WHITE);
        output2.setForeground(Color.WHITE);
        output3.setForeground(Color.WHITE);
        output4.setForeground(Color.WHITE);
        output5.setForeground(Color.WHITE);
    }

    /*
     * Sets the text of output1
     * 
     * @param text
     */
    public void setOutputOne(String text)
    {
        output1.setText(text);
    }

    /*
     * Sets the text of output2
     * 
     * @param text
     */
    public void setOutputTwo(String text)
    {
        output2.setText(text);
    }

    /*
     * Sets the text of output3
     * 
     * @param text
     */
    public void setOutputThree(String text)
    {
        output3.setText(text);
    }

    /*
     * Sets the text of output4
     * 
     * @param text
     */
    public void setOutputFour(String text)
    {
        output4.setText(text);
    }

    /*
     * Sets the text of output5
     * 
     * @param text
     */
    public void setOutputFive(String text)
    {
        output5.setText(text);
    }

    /*
     * This method will close this JFrame when called.
     */
    public void closeThis()
    {
        this.dispose();
    }

    /*
     * ActionListener for the reset and exit JButtons.
     */
    private class ButtonListener
            implements ActionListener
    {

        @Override
        public void actionPerformed(ActionEvent e)
        {
            if (e.getSource() == reset)
            {
                MainPanel newWindow = new MainPanel();
                closeThis();
            }

            if (e.getSource() == exit)
            {
                System.exit(1);
            }
        }
    }
}
